/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sysmo.server;

/*import java.io.IOException;
import java.io.PrintWriter;*/
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
/*import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;*/

/**
 *
 * @author Derek
 */
public class SysmoServerServlet extends HttpServlet {
   
    /*
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    /*protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {*/
            /* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet SysmoServerServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet SysmoServerServlet at " + request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");
            */
        /*} finally {
            out.close();
        }
    } */

    // <editor-fold defaultstate="collapsed" desc="HttpServlet 方法。单击左侧的 + 号以编辑代码。">
    /* 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    /*@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }*/

    /**
     * 当Java EE服务器启动时应创建此Servlet实例，此Servlet的init()方法
     * 被调用，然后创建相应的sysmo服务器实例。
     * <br />
     *
     * 创建服务器实例时，应该传入实际参数，可通过应用服务器的Servlet
     * 启动参数从外部传递入此Servlet，然后再由此方法传递给sysmo 服务器。
     * <br />
     *
     * 注意：当前此Servlet类只做测试用，最后此类可能会被重写，但与sysmo 
     * 服务器无关。
     *
     * @throws javax.servlet.ServletException
     */
    @Override
    public void init() throws ServletException {
        super.init();
        new Thread() {
            @Override
            public void run() {
                try {
                    SysmoServer sysmo = new SysmoServer(null, null);
                    sysmo.doServerLoop();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    /*
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    /*@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }*/

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    /*@Override
    public String getServletInfo() {
        return "Short description";
    }*/// </editor-fold>



}
